/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dio.com.view;

import dio.com.model.Calculos;
import dio.com.model.bean.PCusto;
import dio.com.model.bean.PVenda;
import dio.com.model.bean.ResumoBean;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author Diogenes
 */
public class TelaPrincipal extends javax.swing.JFrame {

    /**
     * Creates new form TelaPrincipal
     */
    private Calculos calculo;
    private PCusto pcusto;
    private PVenda pvenda;
    

    public TelaPrincipal() {
        ImageIcon icone = new ImageIcon("src/img/cifrao.gif");
        setIconImage(icone.getImage());
        calculo = new Calculos();
        pcusto = new PCusto();
        pvenda = new PVenda(pcusto);
        initComponents();
        setLocationRelativeTo(null);
        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        lblPrecoVenda = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblComissao = new javax.swing.JLabel();
        lblPerdaEstoque = new javax.swing.JLabel();
        lblCartao = new javax.swing.JLabel();
        lblICMSVendas = new javax.swing.JLabel();
        btCalcularPrecoVenda = new javax.swing.JButton();
        lblDespesasOperacionais = new javax.swing.JLabel();
        lblLucro = new javax.swing.JLabel();
        tfComissao = new javax.swing.JFormattedTextField();
        tfICMSVenda = new javax.swing.JFormattedTextField();
        tfCartao = new javax.swing.JFormattedTextField();
        jLabel16 = new javax.swing.JLabel();
        tfLucro = new javax.swing.JFormattedTextField();
        tfDespesasOperacionais = new javax.swing.JFormattedTextField();
        tfPerdaEstoque = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        btResumo = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tfFrete = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tfIPI = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        tfICMSSemFrete = new javax.swing.JFormattedTextField();
        tfPrecoUnitario = new javax.swing.JFormattedTextField();
        tfDesconto = new javax.swing.JFormattedTextField();
        lblICMS = new javax.swing.JLabel();
        tfICMS = new javax.swing.JFormattedTextField();
        lblFrete = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblDesconto = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btCalcularPrecoCusto = new javax.swing.JButton();
        lblIPI = new javax.swing.JLabel();
        lblICMSSemfrete = new javax.swing.JLabel();
        lblPrecoCustoReal = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel17 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        jFormattedTextField1.setText("jFormattedTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("FORMAÇÃO DE PREÇO DE VENDA - CONTABLI");
        setResizable(false);

        jLabel1.setText("Custo");

        jLabel2.setText("Venda");

        lblPrecoVenda.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblPrecoVenda.setText(".");

        jLabel11.setText("Desp.finan./C. de crédito (%)");

        jLabel12.setText("ICMS S/ Vendas (%)");

        lblComissao.setText(".");

        lblPerdaEstoque.setText(".");

        lblCartao.setText(".");

        lblICMSVendas.setText(".");

        btCalcularPrecoVenda.setText("Calcular");
        btCalcularPrecoVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCalcularPrecoVendaActionPerformed(evt);
            }
        });

        lblDespesasOperacionais.setText(".");

        lblLucro.setText(".");

        tfComissao.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfComissaoFocusLost(evt);
            }
        });

        tfICMSVenda.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfICMSVendaFocusLost(evt);
            }
        });

        tfCartao.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfCartaoFocusLost(evt);
            }
        });

        jLabel16.setText("Lucro (%)");

        tfLucro.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfLucroFocusLost(evt);
            }
        });

        tfDespesasOperacionais.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfDespesasOperacionaisFocusLost(evt);
            }
        });

        tfPerdaEstoque.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfPerdaEstoqueFocusLost(evt);
            }
        });

        jLabel13.setText("Comissão S/ Vendas (%)");

        jLabel14.setText("Perda de Estoques (%)");

        jLabel15.setText("Despesas Operacionais (%)");

        jLabel10.setText("Preço de Venda:");

        btResumo.setText("Resumo");
        btResumo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResumoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator2)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblPrecoVenda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfLucro, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                            .addComponent(tfDespesasOperacionais, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tfPerdaEstoque, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tfComissao, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tfICMSVenda, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tfCartao, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblCartao)
                                            .addComponent(lblICMSVendas, javax.swing.GroupLayout.Alignment.TRAILING))
                                        .addComponent(lblComissao, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addComponent(lblPerdaEstoque, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addComponent(lblDespesasOperacionais, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(lblLucro, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(224, 224, 224)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btResumo, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btCalcularPrecoVenda))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel11)
                    .addComponent(lblCartao)
                    .addComponent(tfCartao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(lblICMSVendas)
                    .addComponent(tfICMSVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblComissao)
                    .addComponent(tfComissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblPerdaEstoque)
                    .addComponent(tfPerdaEstoque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDespesasOperacionais)
                    .addComponent(tfDespesasOperacionais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLucro)
                    .addComponent(jLabel16)
                    .addComponent(tfLucro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btCalcularPrecoVenda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btResumo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPrecoVenda)
                    .addComponent(jLabel10))
                .addContainerGap())
        );

        jLabel5.setText("IPI (%)");

        tfFrete.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfFreteFocusLost(evt);
            }
        });

        jLabel6.setText("ICMS (%)");

        jLabel7.setText("Frete (%)");

        tfIPI.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfIPIFocusLost(evt);
            }
        });

        jLabel8.setText("ICMS sem frete (%)");

        tfICMSSemFrete.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfICMSSemFreteFocusLost(evt);
            }
        });

        tfDesconto.setText("");
        tfDesconto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfDescontoFocusLost(evt);
            }
        });

        lblICMS.setText(".");

        tfICMS.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfICMSFocusLost(evt);
            }
        });

        lblFrete.setText(".");

        jLabel4.setText("Descontos (%)");

        lblDesconto.setText(".");

        jLabel3.setText("Preço unitário (R$)");

        btCalcularPrecoCusto.setText("Calcular");
        btCalcularPrecoCusto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCalcularPrecoCustoActionPerformed(evt);
            }
        });

        lblIPI.setText(".");

        lblICMSSemfrete.setText(".");

        lblPrecoCustoReal.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblPrecoCustoReal.setText(".");

        jLabel9.setText("Preço de Custo:");

        jLabel17.setText("Valor");
        jLabel17.setToolTipText("Valor correspondente ao preço unitário");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator4)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addGap(34, 34, 34)
                                        .addComponent(tfPrecoUnitario, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblPrecoCustoReal, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel8))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(tfDesconto, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfIPI, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfICMS, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfFrete, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfICMSSemFrete, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(21, 21, 21)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel17)
                                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(btCalcularPrecoCusto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(lblDesconto)
                                                .addComponent(lblIPI)
                                                .addComponent(lblICMS)
                                                .addComponent(lblFrete)
                                                .addComponent(lblICMSSemfrete)))))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfPrecoUnitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tfDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(lblDesconto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(tfIPI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblIPI))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(lblICMS)
                    .addComponent(tfICMS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfFrete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(lblFrete))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(tfICMSSemFrete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblICMSSemfrete))
                .addGap(18, 18, 18)
                .addComponent(btCalcularPrecoCusto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPrecoCustoReal)
                    .addComponent(jLabel9))
                .addContainerGap())
        );

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jMenu3.setText("Arquivo");
        jMenu3.setEnabled(false);
        jMenuBar1.add(jMenu3);

        jMenu1.setText("Relatórios");
        jMenu1.setEnabled(false);
        jMenuBar1.add(jMenu1);

        jMenu4.setText("Configurações");

        jMenuItem2.setText("Impostos");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem2);

        jMenuBar1.add(jMenu4);

        jMenu2.setText("Ajuda");

        jMenuItem1.setText("Contato");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jSeparator3)
                .addGap(11, 11, 11))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btCalcularPrecoCustoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCalcularPrecoCustoActionPerformed
        sumarizarDadosCustos();
        pcusto.setPrecoDeCusto(calculo.calcularPrecoDeCustoReal(pcusto));
        
        lblPrecoCustoReal.setText("R$ "+String.valueOf(calculo.calcularPrecoDeCustoReal(pcusto)).replace('.', ','));
    }//GEN-LAST:event_btCalcularPrecoCustoActionPerformed

    private void tfDescontoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfDescontoFocusLost
        if (!tfPrecoUnitario.getText().equals("")) {
            lblDesconto.setText(new BigDecimal(tfDesconto.getText().replace(',', '.')).divide(new BigDecimal(100)).
                    multiply(new BigDecimal(tfPrecoUnitario.getText())).setScale(2, RoundingMode.HALF_DOWN).toString());
            //tfIPI.requestFocus();
        }
    }//GEN-LAST:event_tfDescontoFocusLost

    private void tfIPIFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfIPIFocusLost
        //lblIPI.setText(String.valueOf((Double.valueOf(tfIPI.getText()) / 100)*(Double.valueOf(tfPrecoUnitario.getText()) - Double.valueOf(lblDesconto.getText()))));        
        if (!tfIPI.getText().equals("")) {
            lblIPI.setText(new BigDecimal(tfIPI.getText()).divide(new BigDecimal(100)).
                    multiply(new BigDecimal(tfPrecoUnitario.getText()).subtract(new BigDecimal(lblDesconto.getText()).setScale(2, RoundingMode.HALF_DOWN))).toString());
            //tfICMS.requestFocus();
        }

    }//GEN-LAST:event_tfIPIFocusLost

    private void tfICMSFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfICMSFocusLost
        if (!tfICMS.getText().equals("")) {
            //lblICMS.setText(String.valueOf((Double.valueOf(tfICMS.getText()) / 100) * (Double.valueOf(tfPrecoUnitario.getText()) - Double.valueOf(lblDesconto.getText()))));
            lblICMS.setText(new BigDecimal(tfICMS.getText()).divide(new BigDecimal(100)).
                    multiply(new BigDecimal(tfPrecoUnitario.getText()).subtract(new BigDecimal(lblDesconto.getText()).setScale(2, RoundingMode.HALF_DOWN))).toString());
            //tfFrete.requestFocus();
        }

    }//GEN-LAST:event_tfICMSFocusLost

    private void tfFreteFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfFreteFocusLost
        if (!tfFrete.getText().equals("")) {
            //lblFrete.setText(String.valueOf((Double.valueOf(tfFrete.getText()) / 100) * (Double.valueOf(tfPrecoUnitario.getText()) - Double.valueOf(lblDesconto.getText()))));
            lblFrete.setText(new BigDecimal(tfFrete.getText()).divide(new BigDecimal(100)).
                    multiply(new BigDecimal(tfPrecoUnitario.getText()).subtract(new BigDecimal(lblDesconto.getText()).setScale(2, RoundingMode.HALF_DOWN))).toString());
            //tfICMSSemFrete.requestFocus();
        }

    }//GEN-LAST:event_tfFreteFocusLost

    private void tfICMSSemFreteFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfICMSSemFreteFocusLost
        if (tfICMSSemFrete.getText() != null) {
            //lblICMSSemfrete.setText(String.valueOf((Double.valueOf(tfICMSSemFrete.getText()) / 100) * (Double.valueOf(lblFrete.getText()))));
            lblICMSSemfrete.setText(new BigDecimal(tfICMSSemFrete.getText()).divide(new BigDecimal(100)).
                    multiply(new BigDecimal(lblFrete.getText()).setScale(2, RoundingMode.HALF_DOWN)).toString());
            btCalcularPrecoCusto.requestFocus();
        }

    }//GEN-LAST:event_tfICMSSemFreteFocusLost

    private void tfCartaoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfCartaoFocusLost
        if (!tfCartao.getText().equals("")) {
            pvenda.setDespesasFinanceirasCartaoDeCredito(new BigDecimal(tfCartao.getText()));
            //lblCartao.setText(pvenda.getDespesasFinanceirasCartaoDeCredito().toString());
        }
    }//GEN-LAST:event_tfCartaoFocusLost

    private void tfICMSVendaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfICMSVendaFocusLost
        if (!tfICMSVenda.getText().equals("")) {
            pvenda.setIcms_vendas(new BigDecimal(tfICMSVenda.getText()));
            //lblICMSVendas.setText(pvenda.getIcms_vendas().toString());
        }
    }//GEN-LAST:event_tfICMSVendaFocusLost

    private void tfPerdaEstoqueFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfPerdaEstoqueFocusLost
        if (!tfPerdaEstoque.getText().equals("")) {
            pvenda.setPerdaEstoque(new BigDecimal(tfPerdaEstoque.getText()));
            //lblPerdaEstoque.setText(pvenda.getPerdaEstoque().toString());
        }
    }//GEN-LAST:event_tfPerdaEstoqueFocusLost

    private void btCalcularPrecoVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCalcularPrecoVendaActionPerformed
        btCalcularPrecoVenda.requestFocus();
        sumarizarDadosVenda();
        lblPrecoVenda.setText("R$ "+calculo.calcularPrecoDeVenda(pvenda).toString().replace('.', ','));
        mostrarValoresVendas();        
    }//GEN-LAST:event_btCalcularPrecoVendaActionPerformed

    private void tfDespesasOperacionaisFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfDespesasOperacionaisFocusLost
        if (!tfDespesasOperacionais.getText().equals("")) {
            pvenda.setDespesasOperacionais(new BigDecimal(tfDespesasOperacionais.getText()));
            //lblDespesasOperacionais.setText(pvenda.getDespesasOperacionais().toString());
        }
    }//GEN-LAST:event_tfDespesasOperacionaisFocusLost

    private void tfLucroFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfLucroFocusLost
        if (!tfLucro.getText().equals("")) {
            pvenda.setLucro(new BigDecimal(tfLucro.getText()));
            //lblLucro.setText(pvenda.getLucro().toString());
        }

    }//GEN-LAST:event_tfLucroFocusLost

    private void tfComissaoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfComissaoFocusLost
        if (!tfComissao.getText().equals("")) {
            pvenda.setComissaoSemVendas(new BigDecimal(tfComissao.getText()));
            //lblComissao.setText(pvenda.getComissaoSemVendas().toString());
        }

    }//GEN-LAST:event_tfComissaoFocusLost

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        Configuracoes c = new Configuracoes(this, rootPaneCheckingEnabled);
        c.setVisible(rootPaneCheckingEnabled);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        Sobre s = new Sobre(this, rootPaneCheckingEnabled);
        s.setVisible(rootPaneCheckingEnabled);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void btResumoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResumoActionPerformed
        publicarResumo();
    }//GEN-LAST:event_btResumoActionPerformed


    private void sumarizarDadosCustos() {
        if (!tfPrecoUnitario.getText().equals("")) {
            pcusto.setPrecoUnitario(new BigDecimal(tfPrecoUnitario.getText()));
        }
        if (!tfDesconto.getText().equals("")) {
            pcusto.setDesconto(new BigDecimal(tfDesconto.getText()));
        }
        if (!tfIPI.getText().equals("")) {
            pcusto.setIPI(new BigDecimal(tfIPI.getText()));
        }
        if (!tfICMS.getText().equals("")) {
            pcusto.setICMS(new BigDecimal(tfICMS.getText()));
        }
        if (!tfFrete.getText().equals("")) {
            pcusto.setFrete(new BigDecimal(tfFrete.getText()));
        }
        if (!tfICMSSemFrete.getText().equals("")) {
            pcusto.setICMS_SEM_FRETE(new BigDecimal(tfICMSSemFrete.getText()));
        }
    }

    private void sumarizarDadosVenda() {
        if (!tfCartao.getText().equals("")) {
            pvenda.setDespesasFinanceirasCartaoDeCredito(new BigDecimal(tfCartao.getText()));
        }
        if (!tfICMSVenda.getText().equals("")) {
            pvenda.setIcms_vendas(new BigDecimal(tfICMSVenda.getText()));
        }
        if (!tfComissao.getText().equals("")) {
            pvenda.setComissaoSemVendas(new BigDecimal(tfComissao.getText()));
        }
        if (!tfPerdaEstoque.getText().equals("")) {
            pvenda.setPerdaEstoque(new BigDecimal(tfPerdaEstoque.getText()));
        }
        if (!tfDespesasOperacionais.getText().equals("")) {
            pvenda.setDespesasOperacionais(new BigDecimal(tfDespesasOperacionais.getText()));
        }
        if (!tfLucro.getText().equals("")) {
            pvenda.setLucro(new BigDecimal(tfLucro.getText()));
        }
    }

    private void mostrarValoresVendas() {
        lblCartao.setText(pvenda.getDespesasFinanceirasCartaoDeCredito().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
        lblICMSVendas.setText(pvenda.getIcms_vendas().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
        lblComissao.setText(pvenda.getComissaoSemVendas().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
        lblPerdaEstoque.setText(pvenda.getPerdaEstoque().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
        lblDespesasOperacionais.setText(pvenda.getDespesasOperacionais().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
        lblLucro.setText(pvenda.getLucro().multiply(pvenda.getPrecoVenda()).setScale(4, RoundingMode.HALF_DOWN).toString());
    }
    
    private void publicarResumo() {
        try{
        ResumoBean rb = new ResumoBean();
        rb.setFornecedormercadorias(pcusto.getPrecoUnitario().subtract(new BigDecimal(lblDesconto.getText())).add(new BigDecimal(lblIPI.getText())));
        rb.setFornecedorfrete(new BigDecimal(lblFrete.getText()));
        rb.setPis(pvenda.getPis().multiply(pvenda.getPrecoVenda()));
        rb.setCofins(pvenda.getConfis().multiply(pvenda.getPrecoVenda()));
        rb.setDespesasfinanceiras(new BigDecimal(lblCartao.getText()));
        rb.setIcms(new BigDecimal(lblICMSVendas.getText()).subtract(new BigDecimal(lblICMS.getText())).subtract(new BigDecimal(lblICMSSemfrete.getText())));
        rb.setCsll(pvenda.getContribuicaoSocialSemLucro().multiply(pvenda.getPrecoVenda()));
        rb.setIrpj(pvenda.getImpostoRendaSemLucro().multiply(pvenda.getPrecoVenda()));
        rb.setAdicionalirpj(pvenda.getAdicionalIRPJ().multiply(pvenda.getPrecoVenda()));
        rb.setComissãosvendas(new BigDecimal(lblComissao.getText()));
        rb.setPerdadeestoques(new BigDecimal(lblPerdaEstoque.getText()));
        rb.setDespesasoperacionais(new BigDecimal(lblDespesasOperacionais.getText()));
        rb.setLucro(new BigDecimal(lblLucro.getText()));
        rb.setPrecoVenda(pvenda.getPrecoVenda());
        
        Resumo r = new Resumo(this, rootPaneCheckingEnabled, rb);
        r.setVisible(rootPaneCheckingEnabled);
        }catch(NumberFormatException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(rootPane, "Preecha todos os campos para calcular o resumo","Aviso!",JOptionPane.ERROR_MESSAGE);
        }
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCalcularPrecoCusto;
    private javax.swing.JButton btCalcularPrecoVenda;
    private javax.swing.JButton btResumo;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel lblCartao;
    private javax.swing.JLabel lblComissao;
    private javax.swing.JLabel lblDesconto;
    private javax.swing.JLabel lblDespesasOperacionais;
    private javax.swing.JLabel lblFrete;
    private javax.swing.JLabel lblICMS;
    private javax.swing.JLabel lblICMSSemfrete;
    private javax.swing.JLabel lblICMSVendas;
    private javax.swing.JLabel lblIPI;
    private javax.swing.JLabel lblLucro;
    private javax.swing.JLabel lblPerdaEstoque;
    private javax.swing.JLabel lblPrecoCustoReal;
    private javax.swing.JLabel lblPrecoVenda;
    private javax.swing.JFormattedTextField tfCartao;
    private javax.swing.JFormattedTextField tfComissao;
    private javax.swing.JFormattedTextField tfDesconto;
    private javax.swing.JFormattedTextField tfDespesasOperacionais;
    private javax.swing.JFormattedTextField tfFrete;
    private javax.swing.JFormattedTextField tfICMS;
    private javax.swing.JFormattedTextField tfICMSSemFrete;
    private javax.swing.JFormattedTextField tfICMSVenda;
    private javax.swing.JFormattedTextField tfIPI;
    private javax.swing.JFormattedTextField tfLucro;
    private javax.swing.JFormattedTextField tfPerdaEstoque;
    private javax.swing.JFormattedTextField tfPrecoUnitario;
    // End of variables declaration//GEN-END:variables
}
